package service

import (
	"errors"
	"gorm.io/gorm"
	"week_one/user_srv/models"
)

func GetUseByUsername(username string) (*models.User, error) {
	user := new(models.User)
	return user, models.InitMysql(func(DB *gorm.DB) error {
		res := DB.Where("username = ?", username).First(&user)
		if res.RowsAffected == 0 {
			return errors.New("is not a data")
		}
		return nil
	})
}
func RegisterUser(user *models.User) (*models.User, error) {
	return user, models.InitMysql(func(DB *gorm.DB) error {
		return DB.Create(&user).Error
	})
}
